import React from 'react';
import {
  Form,
  Input,
  Button,
  Table,
  Icon,
  Radio,
  InputNumber,
  Checkbox,
  Modal,
  message,
  notification,
  Affix,
  Upload,
  Select
} from 'antd';

import InnerTable from 'components/DBTable/InnerTable.js';
import ajax from 'utils/ajax';

const FormItem = Form.Item;
const ButtonGroup = Button.Group;
const Option = Select.Option;

var _this;
let flag = 1,switchflag = 1;

/**
 * 内部表格组件
 */
class VersionInner extends InnerTable {
  /**
   * 构造器，好像是用来初始化的？
   * @param props
   */
  constructor(props) {
    super(props);
    this.state.moduleName = 'Version';
  }
  /**
   * 这里好像是用来配置那些按钮之类的
   * @returns {Array}
   */
  onClickView = (e) =>{
    e.preventDefault();
    this.resetFields();
    let selectedRowsPop = this.state.selectedRows[0];    
    if(selectedRowsPop){
      let defaultFileObj = [];
      let defaultFileItem = {};
      defaultFileItem.uid = selectedRowsPop.id;
      defaultFileItem.name = "点击下载文件";
      defaultFileItem.status = "done";
      defaultFileItem.url = selectedRowsPop.patchUrl;
      defaultFileObj.push(defaultFileItem);

      this.setState({fileObjs : defaultFileObj});
    }
    var state={ modalVisible: true, modalTitle: '查看', modalState: this.modalActionState.View,modalForm:true};

    this.setState(state,()=>{
      this.props.look(selectedRowsPop);
    });
  }

  getButtonGroup = () =>{
      let isButtondisabled=false;
      if(this.state.selectedRowKeys.length > 0){  // 是否选择
        isButtondisabled=true;
      }
      if(this.state.selectedRowKeys.length > 1){  // 是否选择了多项
        isButtondisabled=false;
      }
       let editName="修改";
       let addName="新增";
       let deleteName="删除";    
       let button = [<Button key="saveBtn" type="primary" onClick={this.onClickInsert}><Icon type="plus-circle-o" />{addName}</Button>,<Button key='lookBTn' onClick={this.onClickView} disabled={!isButtondisabled}><Icon type="info-circle-o" />查看</Button>,<Button key="editBtn" onClick={this.onClickUpdate} disabled={!isButtondisabled}><Icon type="edit" />{editName}
            </Button>,<Button key="deleteBtn" onClick={this.onClickDelete} disabled={!isButtondisabled}><Icon type="delete" />{deleteName}</Button>]
       return (<ButtonGroup>
        {/* 注意这里, 如果schema中没有定义主键, 不允许update或delete */}
        {button}
    </ButtonGroup>)
  }

}

export default VersionInner;
